import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0
import "base"

Window {
    id: mainWindow
    height: 720
    width: 1280
    visible: true
    flags: Qt.FramelessWindowHint | Qt.WindowMinimizeButtonHint | Qt.Window
    color: Common.colorTransParent

    DropShadow {
        id: rectShadow
        visible: mainArea.visible
        anchors.fill: mainArea
        cached: true
        radius: 10
        samples: 16
        color: Common.colorTextBlack
        source: mainArea
    }

    Rectangle {
        id: mainArea
        anchors.fill: parent
        anchors.margins: 10
        color: Common.colorBG
        radius: 4

        Image {
            id: titleBar
            height: 100
            width: parent.width
            source: "qrc:/resource/bg.jpg"
            MouseArea {
                anchors.fill: parent
                property int startPosX: 0
                property int startPosY: 0
                onPressed: {
                    startPosX = mouseX
                    startPosY = mouseY
                }
                onPositionChanged: {
                    mainWindow.setX(mainWindow.x + (mouseX - startPosX))
                    mainWindow.setY(mainWindow.y + (mouseY - startPosY))
                }
            }

            Image {
                id: logoImage
                source: "qrc:/resource/logo.svg"
                anchors.left: parent.left
                anchors.leftMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                antialiasing: true
                sourceSize.height: parent.height * 0.9
            }

            Label {
                id: chTitle
                text: "工业数字孪生平台"
                font.family: Common.fontMain
                font.pixelSize: 30
                color: Common.colorMain
                anchors.left: logoImage.right
                anchors.leftMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                font.letterSpacing: 5
                anchors.verticalCenterOffset: -20
            }

            Label {
                id: enTitle
                text: "Industrial Digital Twin Platform"
                font.family: Common.fontMain
                font.pixelSize: 16
                color: Common.colorMain
                anchors.horizontalCenter: chTitle.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                anchors.verticalCenterOffset: 20
            }

            Row {
                anchors.right: parent.right
                anchors.top: parent.top
                layoutDirection: Qt.RightToLeft
                spacing: 1
                Repeater {
                    model: ["close", "min"]
                    delegate: Item {
                        height: 30
                        width: 50
                        Image {
                            id: iconImage
                            source: "qrc:/resource/icon_" + modelData + ".svg"
                            anchors.centerIn: parent
                            sourceSize.height: parent.height * 0.8
                            antialiasing: true
                        }
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onExited: parent.scale = 1
                            onEntered: parent.scale = 0.8
                            onClicked: {
                                if(index == 0) {
                                    ViewBridge.closeWindow()
                                    mainWindow.close()
                                } else {
                                    mainWindow.showMinimized()
                                }
                            }
                        }
                    }
                }
            }
        }

        Item {
            id: leftBar
            anchors.top: titleBar.bottom
            anchors.left: parent.left
            anchors.bottom: parent.bottom
            width: 500
            Row {
                id: selectTitle
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 20
                spacing: 20
                Image {
                    source: "qrc:/resource/arrow_left.svg"
                    height: 35
                    width: 35
                    enabled: modelSelectView.currentIndex != 0
                    MouseArea {
                        anchors.fill: parent
                        hoverEnabled: true
                        onExited: parent.scale = 1
                        onEntered: parent.scale = 0.8
                        onClicked: {
                            modelSelectView.currentIndex = modelSelectView.currentIndex - 1
                        }
                    }
                }

                Label {
                    text: modelSelectView.currentIndex == 0 ?
                              "配准/分割点云" : modelSelectView.currentIndex == 1 ?
                                  "选择配合面" : "特征提取"
                    verticalAlignment: Label.AlignVCenter
                    horizontalAlignment: Label.AlignHCenter
                    font.family: Common.fontMain
                    anchors.verticalCenter: parent.verticalCenter
                    font.pixelSize: 18
                    color: Common.colorTextBlack
                    width: 150
                }
                Image {
                    source: "qrc:/resource/arrow_right.svg"
                    height: 35
                    width: 35
                    enabled: modelSelectView.currentIndex != 2
                    MouseArea {
                        anchors.fill: parent
                        hoverEnabled: true
                        onExited: parent.scale = 1
                        onEntered: parent.scale = 0.8
                        onClicked: {
                            modelSelectView.currentIndex = modelSelectView.currentIndex + 1
                        }
                    }
                }
            }

            Rectangle {
                id: cutLine
                anchors.left: modelSelectView.left
                anchors.right: modelSelectView.right
                anchors.top: selectTitle.bottom
                anchors.topMargin: 20
                height: 1
                LinearGradient {
                    anchors.fill: parent
                    start: Qt.point(0, 0)
                    end: Qt.point(width, 0)
                    gradient: Gradient {
                        GradientStop{position: 0.0; color: "white"}
                        GradientStop{position: 0.5; color: Common.colorMain}
                        GradientStop{position: 1.0; color: "white"}
                    }
                }
            }

            SwipeView {
                id: modelSelectView
                anchors.top: cutLine.bottom
                anchors.bottom: logArea.top
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.margins: 5
                interactive: false
                clip: true

                RegistPage {
                }
                SelectPage {

                }
                AnalysePage {

                }
            }

            ScrollView  {
                id: logArea
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.margins: 5
                height: 110
                background: Rectangle {
                    color: Common.colorTransParent
                    border.color: Common.colorMain
                    radius: 4
                }
                TextArea {
                    font.family: Common.fontMain
                    font.pixelSize: 14
                    wrapMode: TextArea.WrapAnywhere
                    text: "准备就绪..."
                    enabled: false
                }
            }
        }

        Item {
            id: widgtArea
            anchors.right: parent.right
            anchors.left: leftBar.right
            anchors.top: titleBar.bottom
            anchors.bottom: parent.bottom
            anchors.margins: 5
        }
    }

    Connections {
        target: ViewBridge
        onWidgetReady: {
            ViewBridge.resizeEmbeddedWidget(widgtArea.x + 10, widgtArea.y + 10, widgtArea.width, widgtArea.height)
        }
    }
}
